IOS device based webpage blocking method and device

ABSTRACT

An iOS device-based webpage blocking method, being applied to an iOS device comprising application programs and system components, the method comprising: an application program conducts sub-classing on a system default uniform resource locator (URL) caching object to obtain control of a network request; matching the URL character string parsed from the request message with a link character string; if the matching is successful, then generating pseudo response data and displaying according to the pseudo response data, thus blocking webpage advertisements or malicious webpages, reducing occupying of system resources and network resources, improving system operation speed and speed and smoothness of user network access, and lowering device power consumption. The present invention solves the problem in the prior art of resources being occupied by webpage advertisements or malicious webpages.

FIELD OF THE INVENTION

The present invention relates to computer technology field, inparticular, to a method and a device for blocking a webpage based on aniOS device.

BACKGROUND OF THE INVENTION

With rapidly development of Internet, iOS (an operation systemresearched and developed by Apple Inc.) is becoming more and morepopular. An iOS device is a device which uses iOS as its operationsystem, including iPhone, iPad, iPod Touch and Apple TV, etc. Whenvisiting a website via a web browser in an iOS device, a user maytrigger a preset webpage ad or a malicious website. By using the form ofad banner, text links or multimedia, the webpage ad delivers adinformation to users via network.

During the process of implementing this invention, the present inventorsdiscovered following disadvantages in prior art:

After being triggered, the preset webpage ad or malicious webpage in awebsite will occupy system resources and network resources so as toreduce running speed of the system and speed of visiting a website for auser; when it comes to a mobile device, quantity of electric charge ofthe device may be consumed by a webpage ad or a malicious website.Moreover, by being triggered, a malicious website could plant virus to aclient to monitor the client, steal privacy information, such ascontacts and personal information, from the client, even locate a userwho uses the client side; in this way, there exist many potential risksin prior art.

SUMMARY OF THE INVENTION

The present object of the present invention is to provide a method and adevice for blocking a webpage based on an iOS device to resolve issue inprior art that resources may be occupied by triggering a webpage ad or amalicious webpage.

Thus, according to one aspect of the present invention, there isprovided a method for blocking a webpage based on an iOS device, and themethod is used in an iOS device which includes an application programand a system component, the method including following steps:

S1) starting the application program, creating a subclass object of URL(Uniform Resource Locator) cache class, pointing the subclass object asa cache object of uniform resource locator, in which the cache object ofuniform resource locator is a visited object when a web request is sentby the system component;

S2) obtaining, by the application program, HTTP (Hypertext transferprotocol) address entered by a user, generating a first requestinformation according to the HTTP address, sending the first requestinformation to the system component;

S3) monitoring, by the application program, a web request sent by thesystem component via the subclass object;

S4) when the web request is successfully monitored by the applicationprogram, the application program obtaining a second request informationfrom the system component, parsing the second request information toobtain an uniform resource locator character string included in thesecond request information;

S5) matching, by the application program, a link character string withthe parsed uniform resource locator character string, if the match issuccess, executing Step S6; if the match fails, executing Step S7;

S6) generating, by the application program, a fake-response data,returning the fake-response data to the system component, displaying thefake-response data via the system component, returning to Step S3; and

S7) sending, by the application program, the second request informationto a web server, receiving a response information returned by the webserver, sending the response information to the system component, andreturning to Step S3.

According to the other aspect of the present invention, there isprovided an iOS device which includes an application program and asystem component, wherein the application program includes:

an initialization module which is configured to create a subclass objectof URL cache class when the application program is started, point thesubclass object as a URL cache object, the URL cache object is a objectvisited by the system component when the component sends web request;

a request module which is configured to obtain an HTTP address enteredby a user, generate the first request information according to the HTTPaddress, sent the first request information to the system component;

a monitor module which is configured to monitor a web request sent bythe system component via the subclass object created by theinitialization module;

a parsing module which is configured to obtain the second requestinformation from the system component when the monitor module detectsthe web request sent by the system component, parse the second requestinformation to obtain a URL character string included in the secondrequest information;

a match module which is configured to match the link character stringwith the URL character string parsed by the parsing module;

a fake module which is configured to generate fake-response data whenthe link character string and the URL character string are matchedsuccessfully by the match module, return the fake-response data to thesystem component, display the fake-response data via the systemcomponent; and

a first response module which is configured to send the second requestinformation to a website sever when the match made by the match modulefails, receive a response information returned by the website sever, andsend the response information to the system component.

The merits of the present invention are that subclass a URL cache objectdefaulted by the system so as to transmit the control power of a websiterequest from iOS system to an application program; the applicationprogram matches a link character string with a URL character stringparsed form the request information, when the link character string andthe URL character string are matched successfully, fake response data isgenerated, website is displayed according to the fake response data, inthis way, webpage ad and malicious website may be blocked so as tooccupy less system resources and network resources, improve runningspeed of the system and speed of visiting a website for a user and useless quantity of electric charge of the device.

The present invention provides a technical solution that can resolve theissue in prior art that resources are occupied because webpage ad ormalicious website is triggered.

BRIEF DESCRIPTION OF ACCOMPANYING DRAWINGS

FIG. 1 is a structure diagram of an iOS device according to the presentinvention;

FIG. 2 is a method flowchart of blocking a website based on an iOSdevice according to the present invention;

FIG. 3 is a flowchart of an application program matches link characterstrings according to the present invention;

FIG. 4 is a structure diagram of an iOS device according to the presentinvention.

EMBODIMENTS

The technical solution in the Embodiments of the present invention isfurther described more clearly and completely with the drawings in theEmbodiments of the present invention. Apparently, Embodiments describedare just a few of all Embodiments of the present invention. On the basisof Embodiments of the invention, all other related Embodiments made bythose skilled in the art without creative work belong to the scope ofprotection of the invention.

The present invention provides a method for blocking a website based onan iOS device, which is applied in an iOS device including anapplication program and a system component, as shown in FIG. 1, theapplication program creates a subclass object of a URL cache class inprocess of initializing, the subclass object is pointed as a URL cacheobject, the URL cache object is an object which, defaulted by thesystem, is configured to cache data, and the URL cache is visited whenthe web request is sent.

For instance, when the URL cache class is a NSURLCache class, a subclassof the NSURLCache class may be created, which is a FTURLCache class, anobject cache of the FTURLCache is created, the cache object is pointedas a NSURLCache object defaulted by the system. Because a web request inSDK (Software Development Kit) usually visits a NSURLCache objectdefaulted by the system, the cache object is visited by the web requestin SDK after the cache object is pointed as the NSURLCache objectdefaulted by the system, in this way, the web request may be monitoredand processed by the cache object.

After the application program is started, a first request information isgenerated according to an HTTP (Hyper Text Transfer Protocol) addressentered by an user, the first request information is sent to the systemcomponent, a web request is sent via the system component; a subclassobject of the URL cache class created by the application program, whichis for instance a cache object, is visited by the system; the subclassobject obtains a second request information from the system component,and returns a response information to the system component; the systemcomponent displays according to the response information. The controlpower of the web request could by transmitted from an iOS system to theapplication program by creating and pointing the subclass object of URLcache class, in this way, a webpage ad and a malicious webpage could beblocked because a request and web data are processed by the applicationprogram.

Based on an iOS device, a method for blocking a webpage in an Embodimentof the present invention, as shown in FIG. 2, includes following steps.

Step 201, the application program is started, initialization isprocessed.

Specifically, in an iOS system, cache data is usually stored in adefaulted USURLCache object by the system component. The NSURLCacheobject is a global shared object which may be visited by all webrequests in SDK, an NSURLRequest object is mapped to anNSCachedURLResponse object by a cachedResponseForReques method in theNSURLCache object, and the NSCachedURLResponse object is returned. Inwhich, the system component may be a UIWebView component.

Based on the system above, a subclass of the NSURLCache class may bedefined in the present Embodiment, which is the FTURLCache class, acachedResponseForRequest method is rewritten in the FTURLCache class,when the application program is started, the following method is enteredvia an AppDelegate entry:

(BOOL)application(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionay*)launchOptions

In the above method, the object cache of the FTURLCache class may becreated, by invoking a setSharedURLCache method, the cache object ispointed as the defaulted NSURLCache object and filled into the system.

Because the defaulted NSURLCache object is usually visited by the webrequest in SDK, the cache object will be visited by the web request inSDK after the cache object is pointed as the defaulted NSULCache object,thus, the cache object could monitor and process the web request.

Step 202, an HTTP address entered by a user is obtained by theapplication program, according to the HTTP address, the first requestinformation is generated, the first request information is sent to thesystem component, the web request is sent to the web server via thesystem component.

Specifically, the HTTP address entered by the user could be obtained bythe application program, as an URL character string in the first requestinformation, the HTTP address generates the first request information,according to the first request information, the web request is sent tothe web server by invoking a method in the system component.

In which the system component is a UIWebView component, the firstrequest information is an illustration of the NSURLRequest object whichincludes an URL character string, cache way information and a timeoutperiod.

For example, when the HTTP address, obtained by the application program,is “www.aaa.com.cn”, the generated first request information is

“<NSURLRequesturl:http://www.aaa.com.cn/cachePolicy:0NSTimeInterval:10000>”.

In which the URL character string is “http://www.aa.com.cn/”, the cacheway information is 0, and the timeout period is 10000.

The application program invokes a loadRequest method in the UIWebViewcomponent, makes the first request information as a parameter of theloadRequest method to send the web request to the web server.

Step 203, the web request sent by the system component is monitored bythe application program.

Specifically, the web request sent by the system component may bemonitored by the application program via the cache object. The cacheobject is pointed as the defaulted NSURLCache object by the applicationprogram in process of initializing, and the defaulted NSURLCache objectis usually visited by the web request, thus, when the web request issent by the system component, the web request will visit the cacheobject and be monitored by the application program.

For instance, when the loadRequest method in the web component isinvoked, according to the request information “<NSURLRequesturl:http://vvww.aaa.com.cn/cachePolicy:0NSTimeInterval:10000>”, a webrequest is sent, and the defaulted NSURLCache object, which is the cacheobject created in Step 201, is visited, thus, the web request ismonitored by the application program.

Step 204, when the web request sent by the system component issuccessfully monitored by the application program, the second requestinformation is obtained from the system component by the applicationprogram, the second request information is parsed to obtain a URLcharacter string included in the second request information.

In which the second request may be same as or different from the firstrequest information; the system component is the UIWebView component,when the cache object is visited by a loadRequest in the UIWebViewcomponent, the web request sent by the UIWebView component issuccessfully monitored by the application program, the second requestinformation from the UIWebView component may be received, the URLcharacter string is parsed from the second request information byinvoking a cachedResponseForRequest method in the cache object.

For instance, when the second request information obtained from theUIWebView component by the application program is “<NSURLRequesturl:http://www.aaa.com.cn/cachePolicy:0NSTimeInterval:10000>”, the URLcharacter string parsed from the second request information by theapplication program is “http://www.aaa.com.en/”;

When the second request information obtained from the UIWebViewcomponent by the application program is “<NSURLRequesturl:http://gongyi.qq.com/logo.png/cachePolicy:0NSTimeInterval:10000>”,the URL character string parsed from the second request information bythe application program is “http://gongyi.qq.com/logo.png/”;

Step 205, a preset link match file is opened by the application program,and an initial position of the link match file is made as a currentposition.

Specifically, by invoking an open method, the preset link match file isopened by the application program, the initial position is made as thecurrent position. In which, the link match file may includes a line ofor lines of link character strings, the link character string may be acharacter string which meets a preset form.

For instance, the preset link match file filter.txt may be opened by theapplication program by invoking the open method.

Step 206, started from the current position, a line of link characterstring in the link match file is read by the application program, andthe current position is updated to the end of the link character string.

Specifically, starting from the current position, the applicationprogram may read a line of link character string from the link matchfile by invoking a read method, and the current position is updated tothe end of the link character string.

For instance, the line of the link character string read by theapplication from the link match file filter.txt is “http://*.ad.*/*”.

Step 207, the read link character string is matched by the applicationprogram with the parsed URL character string, execute Step 208 ifmatched successfully; execute Step 209 if matched unsuccessfully.

Specifically, the application program may match the read link characterstring with the parsed URL character string by invoking a MatchUrlmethod.

For instance, when the URL character parsed by the application programis “http://www.aaa.com.cn/”, the application program matches the readcharacter string “http://*.ad.*/*” with “http://www.aaa.com.cn”;

when the URL character parsed by the application program is“http://gongyi.qq.com/logo.png/”, the application program matches theread character string “http://*.ad.*/*” withhttp://gongyi.qq.com/logo.png/.

Step 208, fake response data is generated by the application program andreturned to the system component, the fake-response data is displayed bythe system component, Step 203 is returned.

Specifically, according to a local resource file, a fake Response handleis encapsulated by the application program as the fake response datawhich is returned to the system component, the Response handle isconfigured to fake the response data returned by the web server, inwhich the Response handle is an illustration of an NSURLResponse objectincluding a header field, a content, and cache way information; thesystem component is the UIWebView component; the content in Responsehandle is a data content corresponding to the local resource file.Preferably, the application program may obtain a type of the resourcefile corresponding to the parsed URL character string, and acorresponding local resource file is chosen according to the type of theresource file, the fake Response handle is generated according to thechosen local resource file.

For instance, the fake response data which is generated and returned bythe application program is the fake Response handle:

“<NSURLResponse headerField:(NSDictionary)0x00128003 data:(NSData*)datacacheStoragePolice:0>”,

in which the header field is (NSDictionay)0x00128003, the content is(NSData*)data, the cache way information is 0.

Correspondingly, by loading the system component, the applicationprogram could display the local resource file corresponding to thereceived fake response data.

In the present Embodiment, the application program may display atransparent image whose pixel is 1*1 by loading the system component,prompt a user that an ad or a delicious website is blocked by popping upa window, or replace a dynamic image, a video resource or an audioresource corresponding to the web request with a static image. Inaddition, the application program may replace a resource imagecorresponding to the web request with a local image, replace a remotevideo resource corresponding to the web request with a local videoresource, and replace a remote audio resource corresponding to the webrequest with a local audio resource.

Step 209, the application program determines whether the currentposition is the final position of the link match file, if yes, executeStep 210; otherwise, execute Step 206.

Step 210, the application program determines whether a resource filecorresponding to the parsed URL character string is stored in the localcache, if yes, execute Step 211; otherwise, execute Step 212.

Specifically, by invoking the cachedResponseForRequest method, thecachedResponseForRequest in the NSURLCache class, in the super class ofcache object, the application program may determine whether the resourcefile corresponding to the parsed URL character string is stored in thelocal cache.

For instance, when the parsed URL character string is“http://gongyi.qq.com/logo.png/”, a png image named logo is searched bythe application program from the local cache.

Step 211, the resource file, corresponding to the parsed URL characterstring, in the local cache is sent to the system component by theapplication program and displayed via the system component, Step 203 isreturned to.

In which, the system component is the UIWebView component.

For instance, when the URL character string is“http://gongyi.qq.com.logo.png/”, the png image named logo which isstored in the local cache is sent to the UIWebView component by theapplication program and is displayed via the UIWebView component.

Step 212, the second request information is sent to the web server bythe application program, the response information returned by the webserver is received, and the response information is sent to the systemcomponent, Step 203 is returned.

Specifically, the application may invoke the cachedResponseForRequestmethod in super class of cache object, i.e. cachedResponseForRequestmethod in NSURLCache class, to obtain an NSCachedURLResponse objectreturned by the cacheResponseForRequest method, which is the responseinformation. The response information is returned to the systemcomponent by the application program.

In which, the response information returned by the web server may be aresponse data, the response data may include a type of resource, a sizeof resource, resource name and resource data, the resource may be binarydata.

Correspondingly, after the received response data is returned to thesystem component by the application program, corresponding resource filemay be displayed via the system component, the system component is theUIWebView component.

For instance, when the response data returned by the web server is “thetype of resource=png image, the size of resource=20 KB, the resourcename=logo and the resource data=1011110110001111010”, the png imagenamed logo is displayed by the application program via the UIWebViewcomponent.

Moreover, the response information returned by the web server may bewebsite data, the website data may include one or more resource fileaddresses.

Correspondingly, after returned to the system component by theapplication program, the received website data is parsed by the systemcomponent to get a resource file address in the website data, acorresponding request information is generated according to the resourcefile address, the request information is configured to send a webrequest.

Specifically, the received website data is parsed by the systemcomponent via a loadHTMLString method to obtain the resource fileaddress in the website data. Moreover, a corresponding requestinformation is generated by the system component according to theobtained resource file address, the request information is configured tosend a web request and visit the default NUSURLCache object which is thecache object created in Step 201.

In which, the request information generated by the system component isan example of the USURLRequest object, which may include URL characterstring, cache way information and overtime, the system component is theUIWebView component.

For instance, the resource file address parsed by the system componentfrom the received website data is “http://gongyi.qq.com/logo.png/”, thegenerated request information is

“<NSURLRequesturl:http://gongyi.qq.com/logo.png/cachePolicy:0NSTimeInterval:10000>”.

Correspondingly, after the web request is monitored successfully by theapplication program, the second request information, which is generatedby the system component according to the resource file address, isobtained from the system component and processed by the applicationprogram, that is form Step 204 to Step 212 in the present Embodiment areexecuted.

It is important to note that, as shown in FIG. 3, Step 207 of theEmbodiment in the present invention, which is that the read linkcharacter string is matched with the parsed URL character string by theapplication program, may include following steps:

Step 301, the read link character string is parsed by the applicationprogram to obtain a valid character string.

Specifically, a placeholder in the link character string may be deletedby the application program to obtain a valid link character string.

For instance, the read link character string is “http://*.ad.*/*”, thevalid character string “ad” is obtained after the placeholders in thelink character string are deleted.

Step 302, a first character of the valid character string is extractedby the application program.

For example, when the valid character string is ad, the extracted firstcharacter of the valid character string is a.

Step 303, a current traversal subscript is initialized by theapplication program.

In the Embodiment of the present invention, the current traversalsubscript is initialized as 0 by the application program.

Step 304, according to the current traversal subscript, a correspondingcharacter is extracted by the application program from the URL characterstring.

In which, different characters in the URL character string correspond todifferent traversal subscripts respectively, the first character stringcorresponds to the traversal subscript 0. The URL character string isthe URL character string parsed by the application program.

For example, when the URL character string is “http://www.aaa.com.cn/”and the current traversal subscript is 0, the character extractedcorresponding to the current traversal subscript is “h”.

Step 305, the application program determines whether the extractedcharacter is an ending character, if yes, the read link character stringis matched with the URL character string unsuccessfully; otherwise, Step306 executed.

For instance, when the extracted character is “h”, the applicationprogram determines that the extracted character is not the endingcharacter.

Step 306, the application program determines whether the extractedcharacter is same as the first character of the valid character string,if yes, execute Step 308; otherwise, execute Step 307.

For example, the extracted character is “h”, the first character of thevalid character string is “a”, the application program determines thatthe extracted character is different from the first character of thevalid character string.

Step 307, the current traversal subscript is updated by the applicationprogram, Step 304 is returned.

In the Embodiment of the present invention, the current traversalsubscript may plus 1.

Step 308, starting from a character corresponding to the currenttraversal subscript, the application program intercepts a characterstring whose length is identical to a length of the valid characterstring from the URL character string.

For instance, the URL character string is “http://www.aaa.com.cn/”, whenthe extracted character is the first “a”, the first character of thevalid character string is “a”, and the length of the valid characterstring is 2, the character string intercepted by the application programfrom the character string is “aa”.

Step 309, the application program determines whether the interceptedcharacter string is identical to the valid character string, if yes, theread link character string is matched with the URL character stringsuccessfully; otherwise, return to Step 307.

For instance, when the intercepted character string is “aa” and thevalid character string is “ad”, the application program determines thatthe intercepted character string is different from the valid characterstring.

It is necessary to note that, in other Embodiments of the presentinvention, the read link character string may be split into moresubstrings by the application program according to a wildcard characterin the read link character string, an unprocessed substring is chosenfrom the substrings obtained by splitting, whether the chosen substringis included in the parsed URL character string is determined, if yes,the read link character string is matched with the parsed URL characterstring successfully; otherwise, the chosen substring is marked asprocessed, and whether all of the substring obtained by splitting areprocessed is determined, if yes, the read link character string ismatched with the URL character string unsuccessfully; otherwise,continue to chose an unprocessed character string, and determine whetherthe chosen substring is included in the parsed URL character untilmatched successfully or all of the substrings obtained by splittingaccording to the read link character string are processed.

In addition, a regular expression corresponding to the read linkcharacter string is obtained by the application program, the regularexpression is matched with the parsed URL character string by invokingan NSPredicate class, and an obtained matching result is made as thematching result of matching the link character string with the parsedURL character string.

In the Embodiments of the present invention, by subclassing the defaultURL cache object, the control power of the web request is transmittedfrom the iOS system to the application program; the link characterstring is matched by the application program with the URL characterstring parsed from the request information, when the link characterstring is matched successfully, the fake response data is generated;display content according to the fake response data, in this way, awebpage ad or a malicious website is blocked so as to reduce theoccupation of the system resources and network resources to improverunning speed of the system and the speed of visit by users on one hand,and reduce the quantity of electricity on the other hand.

As shown in FIG. 4, there provides a structural diagram of an iOS deviceaccording to the present invention, which includes an applicationprogram 400 and a system component 500, in which the application program400 includes:

an initialization module 410 which is configured to create a subclassobject of an URL cache class, and point the subclass object as an URLcache object, the URL cache object is an object visited by the systemcomponent when the application program 400 is started;

a request module 420 which is configured to obtain an HTTP addressentered by a user, generate a first request information according to theHTTP address, and send the first request information to the systemcomponent,

in which, specifically, the request module 420 is configured to obtainthe HTTP address entered by a user, make the HTTP address as an URLcharacter string in the first request information to generate the firstrequest information, send a web request to the website server accordingto the first request information by invoking a method in the systemcomponent; the first request information includes an URL characterstring, cache way information and timeout period;

a monitor module 430 which is configured to create the subclass object,via the initialization module 410, to monitor a web request sent by thesystem component;

a parsing module 440 which is configured to obtain a second requestinformation when the web request sent by the system component ismonitored by the monitor module 430, and parse the second requestinformation to obtain an URL character string included in the secondrequest information;

a match module 450 which is configured to match a link character stringwith the URL character string parsed by the parsing module 440;

a fake module 460 which is configured to generate fake response datawhen the match module 450 matches successfully, and return the fakeresponse data to the system component, display the fake response datavia the system component; and

a first response module 470 which is configured to send the secondrequest information to the website server when the match module 450matches unsuccessfully, receive a response information returned by theweb server, and send the response information to the system component.

In which, the response information returned by the web server may be aresponse data which includes a type of resource, a size of resource, aresource name and resource data;

Correspondingly, the first response module 470 is further configured todisplay a resource file corresponding to the response data via thesystem component.

Preferably, the iOS device may include:

a determining module 480 which is configured to determine whether theresource file corresponding to the URL character string parsed by theparsing module 440 is stored in a local cache when the match module 450matches unsuccessfully; and

a second response module 490 which is configured to send the resourcefile, in the local cache, corresponding to the parsed URL characterstring to the system component when the determining module 480determines that the resource file is stored in the local cache, anddisplay the resource file via the system component.

Correspondingly, the first response module 470 is configured to, whenthe determining module 480 determines that the resource filecorresponding to the parsed URL character string is not stored in thelocal cache, send the second request information to the web server,receive a response information returned by the web server, and send theresponse information to the system component.

In the above iOS device, the fake module 460 may include:

a generating sub-module 461 which is configured to generate a fakeresponse handle according to the local resource file when the matchmodule 450 matches successfully, in which, the fake response handle,which includes a header field, a content and cache way information, isconfigured to fake response data returned by the web server,

in which specifically, the generating sub-module 461 is configured toobtain a type of the resource file corresponding to the parsed URLcharacter string, chose a corresponding local resource file according tothe type of the resource file, and generate a fake response handleaccording to the local resource file;

a sending sub-module 462 which is configured to make the response handlegenerated by the generating module sub-module 461 as the fake responsedata which is returned to the system component; and

a displaying sub-module 463 which is configured to display the localresource file corresponding to the fake response data by loading thesystem component.

Preferably, the match module 450 may include a reading sub-module 451, amatch sub-module 452 and a determining sub-module 453, in which,

The reading sub-module 451 is configured to, starting form an initialposition of a preset link match file, read a line of link characterstring, set a current position as a final position of the read linkcharacter string; when triggered by the determining sub-module 453, thereading sub-module 451 reads a line of link character string from thelink match file starting from the current position, and updates thecurrent position to the final position of the read link characterstring;

A match sub-module 452 is configured to match the link character stringread by the reading sub-module 451 with the URL character string parsedby the parsing module, if the sub-module 452 matches successfully, thefake module 460 is triggered; if the sub-module 452 matchesunsuccessfully, the determining sub-module 453 is triggered;

The determining sub-module 453 is configured to determine whether thecurrent position is the final position of the link match file, if yes,the first response module 470 is triggered; otherwise, the readingsub-module 450 is triggered.

Specifically, the match sub-module 452 may be configured to executefollowing operations:

B1) parsing the read link character string to obtain a valid characterstring, extracting a first character of the valid character string, andinitializing a current traversal subscript;

B2) extracting a corresponding character from the parsed URL characterstring according to the current traversal subscript, determining whetherthe extracted character is an ending character, if yes, the read linkcharacter string is matched with the parsed URL character stringunsuccessfully, the determining sub-module 453 is triggered; otherwise,Step B3 is executed;

B3) determining whether the extracted character is identical to thefirst character of the valid character string, if yes, executing StepB5; otherwise, executing Step B4;

B4) updating the current traversal subscript, and returning to Step B2;

B5) starting from the character corresponding to the current traversalsubscript, the match sub-module is configured to intercept a characterstring, a length of which equals the length of the valid characterstring, from the parsed URL character string, determine whether theintercepted character string is identical to the valid character string,otherwise, return to Step B4; if yes, the read link character string ismatched with the parsed URL character string successfully, and the fakemodule 460 is triggered.

In which, the match sub-module 452 initializing the current traversalsubscript specifically includes the current traversal subscript isinitialized as 0 by the match sub-module 452; and

the match module 452 updating the current traversal subscriptspecifically includes the current traversal subscript plus 1.

In addition, the match sub-module 452 may be configured to executefollowing operations:

C1) splitting the read link character string into multiple substrings inaccordance with a wildcard character in the read link character string;

C2) choosing an unprocessed substring from the substring obtained bysplitting;

C3) determining whether the chosen substring is included in the parsedURL character string, if yes, the read link character string is matchedwith the parsed URL character string successfully, the fake module 460is triggered; otherwise, the chosen substring is marked as processed,Step C4 is executed;

C4) determining whether all of the substrings obtained by splitting areprocessed, if yes, the read link character string is matched with theparsed URL character string unsuccessfully, the determining sub-module453 is triggered; otherwise, Step C2 is returned.

Moreover, the match sub-module 452 may be specifically configured toobtain a regular expression corresponding to the read link characterstring, and match the regular expression with the parsed URL characterstring.

According to the present invention, by subclassing the default URL cacheobject, the control power of the web request is transmitted from the iOSsystem to the application program; the link character string is matchedby the application program with the URL character string parsed from therequest information, when the link character string is matchedsuccessfully, the fake response data is generated; display according thefake response data, in this way, a webpage ad or a malicious website isblocked so as to reduce the occupation of the system resources andnetwork resources to improve running speed of the system and the speedof visit by users on one hand, and reduce the quantity of electricity onthe other hand.

Steps of the method in the Embodiments of the present invention may beimplemented via a hardware, a software operated by CPU, or both of them.The software may be installed in a RAM, a Memory, a ROM, an ElectricallyProgrammable ROM, an Electrically Erasable Programmable ROM, a Register,a Hard Disk Drive, a Removable Disk, a CD-ROM, or any storage mediumwhich is acknowledged in the technical field.

While the preferred Embodiments of the present invention have been shownand described herein, it will be obvious for those skilled in the artthat such Embodiments are provided by way of examples only. Any changesand substitutions will be covered by the scope of protection of thepresent invention. It is intended that the following claims define thescope of protection of the present invention.

The invention claimed is:
 1. A method for blocking a webpage based on aniOS device, which is applied in an iOS device comprising an applicationprogram and a system component, wherein, the method comprises followingsteps: S1) starting the application program, creating a subclass objectof URL (Uniform Resource Locator) cache class, and pointing the subclassobject as a cache object of uniform resource locator, in which the cacheobject of uniform resource locator is a visited object when a webrequest is send by the system component; S2) obtaining, by theapplication program, HTTP (Hypertext transfer protocol) address enteredby a user, generating a first request information according to the HTTPaddress, and sending the first request information to the systemcomponent; S3) monitoring, by the application program, a web requestsent by the system component via the subclass object; S4) obtaining, bythe application program, a second request information from the systemcomponent, and parsing the second request information so as to obtain auniform resource locator character string included in the second requestinformation, when the web request is successfully monitored by theapplication program; S5) matching, by the application program, a linkcharacter string with the parsed uniform resource locator characterstring, if the match is success, executing Step S6; while if the matchfails, executing Step S7; S6) generating, by the application program, afake-response data, returning the fake-response data to the systemcomponent, displaying the fake-response data via the system component,and returning to Step S3; and S7) sending, by the application program,the second request information to a web server, receiving responseinformation returned from the web server, sending the responseinformation to the system component, and returning to Step S3, whereinStep S5 specifically comprises: A1) reading, by the application program,a line of link character string from the very beginning of an initialposition of a preset link match file, and setting a current position asa final position of the read link character string; A2) matching, by theapplication program, the read link character string with the parsed URLcharacter string, if matching successfully, executing Step S6; while ifmatching unsuccessfully, executing Step A3; A3) determining, by theapplication program, whether the current position is an ending positionof the link match file, if yes, executing Step S7; otherwise, executingStep A4; and A4) reading, by the application program, a line of linkcharacter string from the link match file starting from the currentposition, updating the current position with a final position of theread link character string, and returning to Step A2.
 2. The method asclaimed in claim 1 wherein Step S2 specifically comprises: obtaining, bythe application program, the HTTP address entered by an user, making theHTTP address as the URL character string in the first requestinformation so as to generate the first request string, and sending aweb request to the web server by invoking the method in the systemcomponent according to the first request information, in which the firstrequest information comprises an URL character string, cache wayinformation and an overtime period.
 3. The method as claimed in claim 1wherein Step A2 specifically comprises: B1) parsing, by the applicationprogram, the read link character string so as to obtain a validcharacter string, extracting a first character from the valid characterstring, and initializing a current traversal subscript; B2) extracting,by the application program, a corresponding character from the parsedURL character string according to the current traversal subscript, anddetermining whether the extracted character is an ending character, ifyes, determining that the read link character string is matched with theparsed URL character string unsuccessfully, then executing Step A3;otherwise, executing Step B3; B3) determining, by the applicationprogram, whether the extracted character is identical to the firstcharacter of the valid character string, if yes, executing Step B5;otherwise, executing Step B4; B4) updating, by the application program,the current traversal subscript, and returning to Step B2; and B5)extracting, by the application program, a character string, a length ofwhich equals a length of the valid character string, from the parsed URLcharacter string starting from a character corresponding to the currenttraversal subscript, and determining whether the extracted characterstring is identical to the valid character string, if no, returning toStep B4; while if yes, determining that the read link character stringis matched with the parsed URL character string successfully, executingStep S6.
 4. The method as claimed in claim 1 wherein Step A2specifically comprises: C1) splitting, by the application program, theread link character string into multiple substrings in accordance with awildcard character in the read link character string; C2) choosing, bythe application program, an unprocessed substring from the substringsobtained by splitting; C3) determining, by the application program,whether the chosen substring is included in the parsed URL characterstring, if yes, determining that the read link character string ismatched with the parsed URL character string successfully, executingStep S6; otherwise, marking the chosen substring as processed, executingStep C4; and C4) determining, by the application program, whether all ofthe substrings obtained by splitting are processed, if yes, determiningthat the read link character string is matched with the parsed URLcharacter string unsuccessfully, executing Step A3; otherwise, returningto Step C2.
 5. The method as claimed in claim 1 wherein the applicationprogram generating the fake response data and returning the fakeresponse data to the system component specifically comprises:generating, by the application program, a fake response handle accordingto a local resource file, and returning the response handle, which is asthe fake response data, to the system component, in which the responsehandle is configured to fake response data returned by the web server,and the response handle includes a header field, a content and cache wayinformation; displaying, by the application program, the fake responsedata via the system component specifically comprises: displaying, by theapplication program, the local resource file corresponding to the fakeresponse data by loading the system component.
 6. The method as claimedin claim 5, wherein, the application program generating a fake responsehandle according to the local resource file specifically comprises:obtaining, by the application program, a type of the resource filecorresponding to the parsed URL character string, choosing acorresponding local resource file according to the type, and generatinga fake response handle in accordance with the local resource file. 7.The method as claimed in claim 1 wherein Step S7 specifically comprises:sending, by the application program, the second request information tothe web server when determining no resource file corresponding to theparsed URL character string is stored in the local cache, receiving aresponse information returned by the web server, and sending theresponse information to the system component; before Step S7, the methodfurther comprises: determining, by the application program, whether theresource file corresponding to the parsed URL character string is storedin the local cache.
 8. The method as claimed in claim 7, wherein, afterthe application program determines whether a resource file correspondingto the parsed URL character string is stored in the local cache, themethod further comprises: sending, by the application program, theresource file corresponding to the parsed URL character string stored inthe local cache to the system component when determining a resource filecorresponding to the parsed URL character string is stored in the localcache, displaying the resource file via the system component, andreturning to Step S3.
 9. The method as claimed in claim 1 wherein theresponse information returned from the web server is response data, theresponse data comprises a type of the resource, a size of the resource,a resource name and resource data; after the application programreceives the response data returned from the web server, and sends theresponse data to the system component, the method further comprises:displaying, by the application program, the resource file correspondingto the response data via the system component.
 10. An iOS device whichincludes an application program and a system component, the iOS devicecomprises: a processor coupled to a memory, the processor to execute theapplication program, wherein the application program comprises: a meansfor initializing to create a subclass object of URL cache class when theapplication program is started, and point the subclass object as a URLcache object, in which the URL cache object is an object visited by thesystem component when the component sends a web request; a means forrequesting to obtain an HTTP address entered by a user, generate thefirst request information according to the HTTP address, and send thefirst request information to the system component; a means formonitoring a web request sent from the system component via the subclassobject created by the means for initializing: a means for parsing toobtain the second request information from the system component when themeans for monitoring module detects the web request sent by the systemcomponent, and parse the second request information so as to obtain aURL character string included in the second request information; a meansfor matching to the link character string with the URL character stringparsed by the means for parsing module; a means for making fake-responseto generate fake-response data when the link character string and theURL character string are matched successfully by the means for matching,return the fake-response data to the system component, and display thefake-response data via the system component; and a means for making afirst response to send the second request information to a websiteserver when the match made by the means for matching fails, receive aresponse information returned from the website sever, and send theresponse information to the system component, wherein said means formatching specifically comprises a means for reading, a means formatching and a means for determining, in which said means for reading isconfigured to read a line of link character string starting from aninitial position of a preset link match file, set a current position asa final character of the read link character string; and read a line oflink character string from the link match file starting from the currentposition when triggered by the means for determining, and update thecurrent position to a final character of the read link character string;said means for matching is configured to match the link character stringread by the means for reading with the URL character string parsed bythe means for parsing, if the link character string read by the meansfor reading matches with the URL character string parsed by the meansfor parsing successfully, triggering the means for making fake-response;while if the link character string read by the means for reading matcheswith the URL character string parsed by the means for parsingunsuccessfully, triggering the means for determining; and the means fordetermining is configured to determine whether the current position isan ending position of the link match file, if yes, triggering the meansfor making the first response; otherwise, triggering the means forreading.
 11. The iOS device as claimed in claim 10 wherein said meansfor requesting is specifically configured to obtain a HTTP addressentered by a user, make the HTTP address as an URL character string inthe first request information so as to generate the first requestinformation, send a web request to the web server by invoking a methodin the system component according to the first request information, inwhich the first request information comprises a URL character string,cache way information and an overtime period.
 12. The iOS device asclaimed in claim 10 wherein the means for matching is specificallyconfigured to following operations: B1) parsing the read link characterstring so as to obtain a valid character string, extracting a firstcharacter of the valid character string, and initializing a currenttraversal subscript; B2) extracting a corresponding character from theparsed URL character string according to the current traversalsubscript, determining whether the extracted character is an endingcharacter, if yes, determining that the read link character string ismatched with the parsed URL character string unsuccessfully, triggeringthe means for determining; otherwise, executing Step B3; B3) determiningwhether the extracted character is identical to a first character of thevalid character string, if yes, executing Step B5; otherwise, executingStep B4; B4) updating the current traversal subscript, and returning toStep B2; and B5) intercepting a character string, a length of which isidentical to the length of the valid character string, from the parsedURL character string starting from the character corresponding to thecurrent traversal subscript, and determining whether the interceptedcharacter string is identical to the valid character string, if no,returning to Step B4; while if yes, determining that the read linkcharacter string is matched with the parsed URL character stringsuccessfully, triggering the means for making the fake-response.
 13. TheiOS device as claimed in claim 10 wherein the means for matching isspecifically configured to execute following operations: C1) splittingthe read link character string into multiple substrings in accordancewith a wildcard character in the read link character string; C2)choosing an unprocessed substring from the substrings obtained bysplitting; C3) determining whether the chosen substring is included inthe parsed URL character string, if yes, determining that the read linkcharacter string is matched with the parsed URL character stringsuccessfully, triggering the means for making the fake-response;otherwise, marking the chosen substring as processed, executing Step C4;and C4) determining whether all of the substrings obtained by splittingare processed, if yes, determining that the read link character stringis matched with the parsed URL character string unsuccessfully,triggering the means for determining; otherwise, returning to Step C2.14. The iOS device as claimed in claim 10 wherein the means for makingthe fake-response comprises: a means for generating a fake responsehandle according to the local resource file when the means for matchingmatches successfully, in which the response handle is configured to fakeresponse data returned by the web server, and the response handlecomprises a header field, a content and cache way information; a meansfor sending to return the response handle, which is generated by themeans for generating and made as the fake response data, to the systemcomponent; and a means for displaying a local resource filecorresponding to the fake response data by loading the system component.15. The iOS device as claimed in claim 14 wherein the means forgenerating is configured to obtain a type of a resource filecorresponding to the parsed URL character string, choose a correspondinglocal resource file according to the type of the resource file, andgenerate a fake response handle according to the local resource file.16. The iOS device as claimed in claim 10 wherein the device furthercomprises: a means for determining whether a resource file correspondingto the parsed URL character string is stored in the local cache when themeans for matching matches unsuccessfully; and the means for making thefirst response is configured to send the second request information tothe web server when the means for determining determines that noresource file corresponding to the URL character string is stored in thelocal cache, receive response information returned from the web server,and send the response information to the system component.
 17. The iOSdevice as claimed in claim 16 wherein the device further comprises: ameans for making a second response which is configured to send theresource file corresponding to the parsed URL character string, which isstored in the local cache, to the system component when the means fordetermining determines that the resource file corresponding the URLcharacter string is stored in the local cache, and display the resourcefile via the system component.
 18. The iOS device claimed in claim 10wherein the response information returned from the web server isresponse data, the response data comprises a type of the resource, asize of the resource, a resource name and resource data; and the meansfor making is configured to display a resource file corresponding to theresponse data via the system component.